/**
 * @(#)ThriftServer.java, 2019/1/4
 * <p/>
 * Copyright 2019 Netease, Inc. All rights reserved.
 * NETEASE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.chengzhi.netty.thrift;

import org.apache.thrift.TProcessorFactory;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.server.TNonblockingServer;
import org.apache.thrift.server.TThreadPoolServer;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TNonblockingServerSocket;
import org.apache.thrift.transport.TServerSocket;
import org.apache.thrift.transport.TTransportException;
import org.apache.thrift.protocol.TBinaryProtocol.Factory;
import org.apache.thrift.server.TThreadPoolServer.Args;

/**
 * @author 阮承志(wb.ruanchengzhi @ mesg.corp.netease.com)
 **/
public class ThriftServer {
    public static void main(String[] args) throws TTransportException {
//        TNonblockingServerSocket socket = new TNonblockingServerSocket(8888);
        PersonService.Processor<PersonServiceImpl> processor = new PersonService.Processor<>(new PersonServiceImpl());
//        TNonblockingServer.Args args1 = new TNonblockingServer.Args(socket);
//        args1.protocolFactory(new TBinaryProtocol.Factory());
//        args1.transportFactory(new TFramedTransport.Factory());
//        args1.processorFactory(new TProcessorFactory(processor));
//        TNonblockingServer server = new TNonblockingServer(args1);

        TServerSocket serverSocket = new TServerSocket(8888);
        Factory factory = new Factory(true, true);
        Args args2 = new Args(serverSocket);
        args2.processor(processor);
        args2.protocolFactory(factory);
        TThreadPoolServer server1 = new TThreadPoolServer(args2);
        server1.serve();
        System.out.println("thrift server start");
    }
}
